// 禁用：非最近一年
const disabledBeforeYear = time => {
  const selectTime = new Date(time).getTime();
  const now = Date.now();
  const oneYearTime = 3600 * 1000 * 24 * 365;
  return (selectTime < now - oneYearTime || selectTime > now);
};

// 禁用：今天之前
const disabledBefore = time => {
  const date = new Date();
  const selectTime = new Date(time).getTime();
  const now = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
  return selectTime < now;
};

// 快捷方式+禁用选择范围
export default {
  shortcuts: [
    {
      text: '昨天',
      onClick(picker) {
        const end = new Date();
        end.setTime(end.getTime() - 3600 * 1000 * 24);
        picker.$emit('pick', [end, end]);
      }
    },
    {
      text: '今天',
      onClick(picker) {
        const start = new Date();
        picker.$emit('pick', [start, start]);
      }
    },
    {
      text: '最近7天',
      onClick(picker) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
        picker.$emit('pick', [start, end]);
      }
    },
    {
      text: '最近30天',
      onClick(picker) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 29);
        picker.$emit('pick', [start, end]);
      }
    }
  ],
  disabledDate: disabledBeforeYear
};

// 禁用选择范围
export const DATERANGE_DISABLED_BEFORE = {
  disabledDate: disabledBefore
};